// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
const _ = db.command;
// 云函数入口函数
exports.main = async (event, context) => {
  const openid = cloud.getWXContext().OPENID
  var {orderNum} = event
    await db.collection("jf_info").where({
      orderNum
    }).update({
      data:{
        isarr:openid,
        state:3
      }
    })
    price =  await db.collection("jf_info").where({
      openid,
      orderNum
    }).get()
    console.log(price.data[0].price)
    gmoney =  await db.collection("jf_register").where({
      openid
    }).get()
    console.log(gmoney)
    console.log(gmoney.data[0])
    console.log(gmoney.data[0].money)
    var allmongey = price.data[0].price*0.8 + gmoney.data[0].money
   
    return await db.collection("jf_register").where({
      openid,
    }).update({
      data:{
        money:allmongey
      }
    })

}